package com.rzjm.exercise.common.base.support;

import java.util.List;

import com.rzjm.exercise.common.base.data.DataTable;
import com.rzjm.exercise.common.context.SpringContextHolder;
import org.springframework.core.ResolvableType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rzjm.exercise.common.base.service.BaseService;
import com.rzjm.exercise.common.log.annotation.Log;

@SuppressWarnings("unchecked")
public interface GenericController<S extends BaseService<T>, T> {
	default S getService() {
		return (S) SpringContextHolder.getBean(ResolvableType.forClass(getClass()).as(GenericController.class).getGeneric(0).resolve());
	}
	
    @Log("下拉框数据查询")
    @ResponseBody
    @GetMapping({"/list/options", "/list/options/{params}"})
    default List<T> selectOptionsList(@PathVariable(required = false) String params) {
    	return getService().selectOptionsList(params);
    }
    
    @Log("选择页数据查询")
    @ResponseBody
    @GetMapping("/list/selectable")
    default DataTable<T> selectSelectablePagination(DataTable<T> condition) {
    	return getService().pageSearch(condition);
    }
}
